package entity;

/**
 * 敌机抽象类
 */
public abstract class Enemy extends FlyingObject {
    protected int speed; // 移动速度
    protected int health; // 生命值
    protected int maxHealth; // 最大生命值
    protected int score; // 击毁得分
    protected boolean alive = true; // 是否存活
    
    @Override
    public void move() {
        y += speed;
    }
    
    @Override
    public boolean isOutOfBounds(int panelWidth, int panelHeight) {
        return y > panelHeight;
    }
    
    @Override
    public boolean isAlive() {
        return alive && health > 0;
    }
    
    /**
     * 扣除生命值
     * @param damage 伤害值
     */
    public void takeDamage(int damage) {
        health -= damage;
        if (health <= 0) {
            health = 0;
            alive = false;
        }
    }
    
    /**
     * 发射子弹
     * @param image 子弹图片
     * @return 子弹对象
     */
    public Bullet shoot(java.awt.Image image) {
        int x = this.x + this.width / 2 - image.getWidth(null) / 2;
        int y = this.y + this.height;
        return new Bullet(x, y, image, 5); // 向下发射
    }
    
    // getter方法
    public int getScore() {
        return score;
    }
    
    public int getHealth() {
        return health;
    }
    
    public int getMaxHealth() {
        return maxHealth;
    }
}